﻿<UserControl x:Class="Studio.DocumentDB.QueryEditorUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Studio.DocumentDB"
             mc:Ignorable="d"
             KeyDown="UserControl_KeyDown"
             d:DesignHeight="300" d:DesignWidth="300"
             IsVisibleChanged="UserControl_IsVisibleChanged">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>
        <ToolBarTray Grid.Row="0" Background="{StaticResource toolBarColour}">
            <ToolBar Band="1" Background="Transparent">
                <Button ToolTip="Execute (F5)" Click="Execute_Click">
                    <Button.Style>
                        <Style TargetType="Button">
                            <Setter Property="IsEnabled" Value="True"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=QueryResults.IsLoading}" Value="true">
                                    <Setter Property="IsEnabled" Value="False"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Style>
                    <Image Source="Images/execute.png"/>
                </Button>
            </ToolBar>
        </ToolBarTray>
        <TextBox Grid.Row="1" AcceptsReturn="True" AcceptsTab="True"
                 Text="{Binding QueryContent, UpdateSourceTrigger=PropertyChanged}" />
        <GridSplitter Grid.Row="1" Height="3" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
        <Grid Grid.Row="2">
            <local:WaitingUserControl>
                <local:WaitingUserControl.Style>
                    <Style TargetType="local:WaitingUserControl">
                        <Setter Property="Visibility" Value="Collapsed"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=QueryResults.IsLoading}" Value="true">
                                <Setter Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </local:WaitingUserControl.Style>
            </local:WaitingUserControl>
            <ListView ItemsSource="{Binding QueryResults, Mode=OneWay}" ScrollViewer.CanContentScroll="False">
                <ListView.Style>
                    <Style TargetType="ListView">
                        <Setter Property="Visibility" Value="Collapsed"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=QueryResults.IsLoaded}" Value="true">
                                <Setter Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ListView.Style>
                <ListView.View>
                    <GridView>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=LineNumber}" Header="  #  " />
                        <GridViewColumn DisplayMemberBinding="{Binding Path=Result}" Header=""/>
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>
    </Grid>
</UserControl>
